package com.javaweb.controller;

/**
 * @desc:
 * @author: Ping
 * @date: 2024/10/22 23:01
 */

import com.javaweb.dao.CategoryDao;
import com.javaweb.model.Category;
import org.springframework.web.bind.annotation.RestController;

import com.javaweb.common.ResponseResult;
import com.javaweb.model.User;
import com.javaweb.service.UserService;
import com.javaweb.service.dto.UserConditionDto;
import com.javaweb.service.dto.UserDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * todo: 分类管理模块
 */
@RestController
@RequestMapping("/blog-api/v0.1/category")
public class CategoryController {
private  CategoryDao categoryService;
    @GetMapping("/list")
    public ResponseResult<List<Category>> list() {
        // 列出所有分类

        List<Category> categories = categoryService.findAllCategories();
        return ResponseResult.ok(categories);
    }

    @PostMapping("/add")
    public ResponseResult<Void> add(@RequestBody Category category) {
        // 新增分类
        categoryService.addCategory(category);
        return  ResponseResult.ok(null);
    }

    @GetMapping("/delete")
    public ResponseResult<Void> delete(@RequestParam String categoryId) {
        // 删除指定分类
        categoryService.deleteCategory(categoryId);
        return  ResponseResult.ok(null);
    }
}

